package com.example.demoss.controller;


///import com.example.demoss.mapper.Dec001Mapper;
import com.example.demoss.entity.Dec;
import com.example.demoss.entity.JanH01;
import com.example.demoss.mapper.Dec001Mapper;
import com.example.demoss.mapper.JanH01Dao;
import com.example.demoss.service.IndexService;

import com.example.demoss.util.Dictionary;
//import com.example.demoss.util.JdbcUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.CompletableFuture;


@Slf4j
@RequestMapping("/indextest")
@RestController
public class IndexController {

    @Autowired
    private JanH01Dao janMapper;




    @Resource
    private IndexService service;


    @GetMapping("/area")
    public void getarea() throws SQLException {


        String tablePrex = "jan_h_";


        CompletableFuture.runAsync(()->{
           for(int i = 1; i<=31;i++){
               String tableName = tablePrex;
               if(i<10){
                   tableName = tablePrex+"0"+String.valueOf(i);
               }else {
                   tableName = tablePrex+String.valueOf(i);
               }
           List<JanH01> list = janMapper.selectAll(tableName);



               for (JanH01 data:list
                    ) {
                   final Dec dec = new Dec();
                   BeanUtils.copyProperties(data,dec);

                   final double v = service.excuteMax(dec);
                   final String aqi = String.valueOf(v);

                   final int i1 = janMapper.updateByMy(tableName,aqi,data.getId());
                   if(i1 == 1){
                       log.info("表名==》{},插入成功=》id{}",tableName,data.getId());
                   }else {
                       log.info("表名==》{},插入失败=》id{}",tableName,data.getId());
                   }


               }


           }

        });








    }





  /*  public void cityOne(String pretablename,int begin,int end) throws SQLException{
        String tableDay = null;

        for(int i = begin;i<= end;i++){

            if(i<10){

                tableDay =  "0"+String.valueOf(i);
            }else {
                tableDay =String.valueOf(i);
            }

            String tableName = pretablename+tableDay;

            log.info("表名=》{}",tableName);
            List<Dec> select =  mapper.selectAll(tableName);


            for (int n =0 ;n<select.size();n++){
                final Dec dec = select.get(n);

                String city = service.areaOne(dec);
                String region = service.regionOne(dec);

                String   columnName="city";
                String   columnName1="region";


                int id = dec.getId();


               int nn =  mapper.updateAllOne(tableName,columnName,columnName1,city,region,id);


                if(nn== 1){
                    log.info("表名={}  id:{},city==>{},region==>{}",tableName,dec.getId(),city,region);
                }
            }

        }
    }

    public void cityTwo(String pretablename,int begin,int end) throws SQLException{
        String tableDay = null;

        for(int i = begin;i<= end;i++){

            if(i<10){

                tableDay =  "0"+String.valueOf(i);
            }else {
                tableDay =String.valueOf(i);
            }

            String tableName = pretablename+tableDay;

            log.info("表名=》{}",tableName);
            List<Dec> select =  mapper.selectAll(tableName);


            for (int n =0 ;n<select.size();n++){
                final Dec dec = select.get(n);

                String city = service.areaOne(dec);
                String region = service.regionTwo(dec);

                String   columnName="city";
                String   columnName1="region";


                int id = dec.getId();
                int nn =  mapper.updateAllOne(tableName,columnName,columnName1,city,region,id);


                if(nn== 1){
                    log.info("表名={}  id:{},city==>{},region==>{}",tableName,dec.getId(),city,region);
                }
            }

        }
    }

    public void cityThree(String pretablename,int begin,int end) throws SQLException{
        String tableDay = null;

        for(int i = begin;i<= end;i++){

            if(i<10){

                tableDay =  "0"+String.valueOf(i);
            }else {
                tableDay =String.valueOf(i);
            }

            String tableName = pretablename+tableDay;

            log.info("表名=》{}",tableName);
            List<Dec> select =  mapper.selectAll(tableName);


            for (int n =0 ;n<select.size();n++){
                final Dec dec = select.get(n);

                String city = service.areaOne(dec);
                String region = service.regionThree(dec);

                String   columnName="city";
                String   columnName1="region";


                int id = dec.getId();
                int nn =  mapper.updateAllOne(tableName,columnName,columnName1,city,region,id);


                if(nn== 1){
                    log.info("表名={}  id:{},city==>{},region==>{}",tableName,dec.getId(),city,region);
                }
            }

        }
    }

    public void cityFour(String pretablename,int begin,int end) throws SQLException{
        String tableDay = null;

        for(int i = begin;i<= end;i++){

            if(i<10){

                tableDay =  "0"+String.valueOf(i);
            }else {
                tableDay =String.valueOf(i);
            }

            String tableName = pretablename+tableDay;

            log.info("表名=》{}",tableName);
            List<Dec> select =  mapper.selectAll(tableName);


            for (int n =0 ;n<select.size();n++){
                final Dec dec = select.get(n);

                String city = service.areaOne(dec);
                String region = service.regionFour(dec);

                String   columnName="city";
                String   columnName1="region";


                int id = dec.getId();
                int nn =  mapper.updateAllOne(tableName,columnName,columnName1,city,region,id);


                if(nn== 1){
                    log.info("表名={}  id:{},city==>{},region==>{}",tableName,dec.getId(),city,region);
                }
            }

        }
    }*/






}
